package cn.gson.crm.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.gson.crm.model.dao.PurchaseTicketDao;
import cn.gson.crm.model.pojo.Purchaseticket;
import cn.gson.crm.model.vo.PurchaseTicketVo;

@Service
@Transactional
public class PurchaseTicketService {
	@Autowired
	private PurchaseTicketDao pDao;

	public List<PurchaseTicketVo> getAllpt(int page, int rows) {
		PageRequest pageRequest = new PageRequest(page - 1, rows);
		List<Purchaseticket> listpo = pDao.getAllPt(pageRequest);
		List<PurchaseTicketVo> listvo = new ArrayList<>();
		for (Purchaseticket p : listpo) {
			listvo.add(returnPtVo(p));
		}
		return listvo;
	}

	public PurchaseTicketVo returnPtVo(Purchaseticket p) {
		PurchaseTicketVo pVo = new PurchaseTicketVo(p.getPtId(), p.getPtAbstract(), p.getPtCaiId(), p.getPtCaiName(),
				p.getPtCusId(), p.getPtCusName(), p.getPtIfPay(), p.getPtMoney(), p.getPtPeriod(), p.getPtRemarks(),
				p.getPtTime(), p.getPtType());
		return pVo;
	}
	
	public Long count() {
		return pDao.count();
	}
	
	public void deletePt(Long id) {
		try {
			pDao.delete(id);
			throw new ServiceException();
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	
	/**
	 * 添加采购发票
	 * @param p
	 */
	public void AddPt(Purchaseticket p) {
		
	}
}
